package org.simplextensions.ui.menu;

import org.simplextensions.annotations.ExtensionPoint;
import org.simplextensions.graph.Graph;
import org.simplextensions.registry.Extension;
import org.simplextensions.registry.ExtensionPointAdapter;
import org.simplextensions.registry.IExtensionPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;

/**
 * 
 * 
 * 
 * 
 * @author Tomasz Krzyzak, <a
 *         href="mailto:tomasz.krzyzak@gmail.com">tomasz.krzyzak@gmail.com</a>
 * @since 2010-05-10 09:57:58
 */
@ExtensionPoint(id = MenuExtensionPoint.ID, extensionClass = { IMenuExtension.class })
public class MenuExtensionPoint extends ExtensionPointAdapter implements IExtensionPoint {

	private static final Logger log = LoggerFactory.getLogger(MenuExtensionPoint.class);

	public static final String ID = "MenuExtensionPoint";

	public static final String IMAGE = "image";
	public static final String PARENT = "parent";
	public static final String ORDER = "order";
	public static final String TYPE = "type";

	private Map<Extension, MenuExtensionMetadata> menuMap = new HashMap<Extension, MenuExtensionMetadata>();

	private Graph menuGraph = new Graph("MenuGraph");

	private MenuExtensionValidator validator = new MenuExtensionValidator();

	public void addExtension(org.simplextensions.registry.Extension extension) {
		if (!menuMap.containsKey(extension)) {
			MenuExtensionMetadata value = new MenuExtensionMetadata(menuGraph, extension);
			menuMap.put(extension, value);
			log.debug("new menu extension: " + value);
		}
	}

	public MenuExtensionMetadata getMenu(String menuId) {
		for (MenuExtensionMetadata memd : menuMap.values()) {
			if (memd.getId().equals(menuId) && memd.getType() == MenuExtensionType.Menu) {
				return memd;
			}
		}
		return null;
	}

}
